package com.kws.commercial.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.kws.commercial.dao.CommercialWorkOrderManagement;
import com.kws.commercial.dao.Info.QueryWorkOrderInfo;
import com.kws.commercial.dao.Rq.CreateWorkOrderRq;
import com.kws.commercial.dao.Rq.QueryWorkOrderPageRq;
import com.kws.commercial.mapper.CommercialWorkOrderMapper;
import com.kws.commercial.service.CommercialWorkOrderService;
import com.kws.common.core.enums.ModelOpType;
import com.kws.common.core.sys.Ksys;
import com.kws.common.core.utils.KConstants;
import com.kws.common.security.utils.SecurityUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <b>CommercialWorkOrderServiceImpl</b>
 *
 * @description: CommercialWorkOrderServiceImpl <br>
 * @date: 2024/10/30 16:53 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Service
public class CommercialWorkOrderServiceImpl extends ServiceImpl<CommercialWorkOrderMapper, CommercialWorkOrderManagement> implements CommercialWorkOrderService {
    private static final Logger logger = LoggerFactory.getLogger(CommercialWorkOrderServiceImpl.class);


    @Override
    public PageInfo<QueryWorkOrderInfo> queryWorkOrderPage(QueryWorkOrderPageRq rq) {
        Long companyId = SecurityUtils.getCompanyId();
        PageHelper.startPage(rq.getPageNum(),rq.getPageSize());
        List<QueryWorkOrderInfo> workOrderList = baseMapper.queryWorkOrderPage(rq.getWorkOrderNo(),rq.getPriority(),rq.getServiceType(),companyId);
        return new PageInfo<QueryWorkOrderInfo>(workOrderList);
    }

    @Override
    public boolean createWorkOrder(CreateWorkOrderRq rq) {
        CommercialWorkOrderManagement commercialWorkOrderManagement = new CommercialWorkOrderManagement();
        commercialWorkOrderManagement.setProjectQuotationId(rq.getProjectQuotationId());
        commercialWorkOrderManagement.setServiceType(rq.getServiceType());
        commercialWorkOrderManagement.setWorkOrderNo(rq.getWorkOrderNo());
        commercialWorkOrderManagement.setTaskDescription(rq.getTaskDescription());
        commercialWorkOrderManagement.setRequiredCompletionTime(rq.getRequiredCompletionTime());
        commercialWorkOrderManagement.setPriority("0");
        commercialWorkOrderManagement.setProcessingPersonnel(rq.getProcessingPersonnel());
        commercialWorkOrderManagement.setStatus("0");
        Ksys.setBasicModelData(commercialWorkOrderManagement,SecurityUtils.getStringUserId(), KConstants.DATA_ENABLE, ModelOpType.CREATE);
        int insert = baseMapper.insert(commercialWorkOrderManagement);
        if (1 == insert){
            return true;
        }
        return false;
    }

    @Override
    public QueryWorkOrderInfo queryWorkOrderById(Long id) {
        return baseMapper.queryWorkOrderById(id);
    }
}
